//
//  LPCSettingManager.m
//  OurJourney
//
//  Created by 李沛池 on 2017/4/5.
//  Copyright © 2017年 Godlike. All rights reserved.
//

#import "LPCSettingManager.h"
#import "LPCDefine.h"

//设置ourJourney字典中存储的以对应方法名为key的value
#define SETTER_CMD(name)  NSMutableDictionary *dicSave = [[NSMutableDictionary alloc] initWithDictionary:[LPCSettingManager dicSettingWalkUp]];\
[dicSave setObject:[NSNumber numberWithBool:name] forKey:@""#name""];\
[DefaultSystemPlist setObject:dicSave forKey:@"OurJourneySetting"];\
[DefaultSystemPlist synchronize];

#define SETTER_CMD_Int(name)  NSMutableDictionary *dicSave = [[NSMutableDictionary alloc] initWithDictionary:[LPCSettingManager dicSettingWalkUp]];\
[dicSave setObject:[NSNumber numberWithInt:name] forKey:@""#name""];\
[DefaultSystemPlist setObject:dicSave forKey:@"OurJourneySetting"];\
[DefaultSystemPlist synchronize];

#define SETTER_CMD_OBJ(name)  NSMutableDictionary *dicSave = [[NSMutableDictionary alloc] initWithDictionary:[LPCSettingManager dicSettingWalkUp]];\
[dicSave setObject:name forKey:@""#name""];\
[DefaultSystemPlist setObject:dicSave forKey:@"OurJourneySetting"];\
[DefaultSystemPlist synchronize];

//返回在ourJourney字典中存储的以对应方法名为key的value
#define RETURN_GETTER_CMD(Default)    return [[LPCSettingManager dicSettingWalkUp] objectForKey:NSStringFromSelector(_cmd)]==nil?Default:[[[LPCSettingManager dicSettingWalkUp] objectForKey:NSStringFromSelector(_cmd)] boolValue];

@implementation LPCSettingManager

singleton_implementation(LPCSettingManager);

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self initData];
    }
    return self;
}

//定制app修改的部分
- (void)initData
{
    _isRandomText = NO;
    _isRandomImage = NO;
    //Godlike为试用版本
    _userId = CURRENT_USERID;
    _appThemeType = AppThemeTypeDefault;
}

//登录成功
+ (void)loginSuccess:(NSDictionary *)dic
{
    
}

//用户退出登录 重置所有数据
+ (void)loginOutWithClearData
{
    [self clearLPCSettingManager];
}

+ (void)clearLPCSettingManager
{
    LPCSettingManager *settingManager = [LPCSettingManager sharedLPCSettingManager];
    settingManager.isLogin = NO;
    settingManager.appThemeType = AppThemeTypeDefault;
}


//获取到walkUp的相关设置字典
+ (NSMutableDictionary *)dicSettingWalkUp
{
    return [DefaultSystemPlist objectForKey:@"OurJourneySetting"];
}

//获取到system的相关设置字典
+ (NSMutableDictionary *)dicSettingSystem
{
    return [DefaultSystemPlist objectForKey:@"SystemSetting"];
}

#pragma mark - 重写setter、getter方法 以达到实时存储在plist中
#pragma mark - setter
- (void)setIsLogin:(BOOL)isLogin
{
    SETTER_CMD(isLogin);
}

//- (void)setIsRandomText:(BOOL)isRandomText
//{
//    SETTER_CMD(isRandomText);
//}
//
//- (void)setIsRandomImage:(BOOL)isRandomImage
//{
//    SETTER_CMD(isRandomImage);
//}


#pragma mark - getter
- (BOOL)isLogin
{
    RETURN_GETTER_CMD(NO)
}

//- (BOOL)isRandomText
//{
//    RETURN_GETTER_CMD(YES);
//}
//
//- (BOOL)isRandomImage
//{
//    RETURN_GETTER_CMD(YES);
//}


@end
